<!-- 异常记录 -->
<template>
	<view>
	<view class="main">
		<view class="avatar-info">
			<input type="text"
			  placeholder="请输入运单号、品名、收货人电话查询"
			  v-model="inputValue"
			  class="contact-info"
			  @input="searchItemsByKeyword">
			  </input>
		</view>
		<div v-if="items.length === 0" class="empty-state">
		    <img src="/../../../static/空数据.png" style="height:150px;width: 180px;">
			<p style="font-size: 20px;text-align: center;">暂无数据!</p>
		</div>
		<div v-else>
		<div v-for="(item, index) in queryResult" :key="index" class="outer-content-list" >
			<view class="content">
				<view class="content-list">
					<p class="avatar-list">
					<span class="options-yun">运单号</span>
					<!-- <span class="delivery-options" v-if="item.waybillNumber!=null">{{item.waybillNumber}}</span> -->
					<span class="delivery-options1">{{item.waybillNumber}}</span>
					<span class="price" v-if="item.deleted===1">已撤销</span>
					<span class="price" v-if="item.abnormalStatus===1 &&item.deleted===0">未处理</span>
					<span class="price" v-if="item.abnormalStatus===2 &&item.deleted===0">未完结</span>
					<span class="price" v-if="item.abnormalStatus===3 &&item.deleted===0">已完结</span>
					
					</p>
				</view>
			</view>
		<view class="content-list-1">
			<p class="avatar-list">
			<span class="shipment">货件信息</span>
			<span class="description" v-if="item.description!=null">{{item.description}}</span>
			<span class="algebra" v-if="item.number!=null">{{item.number}}件</span>
			<span class="one"> 1 </span>
			<span class="kg" v-if="item.weight!=null">{{item.weight}}kg</span>
			<span class="meter" v-if="item.volume!=null">{{item.volume}}m</span>
			</p>
		</view>
		<view class="content-list-6">
			<p class="avatar-list">
			<span class="options">收货人</span>
			<span class="delivery-options" v-if="item.putUserName!=null">{{item.putUserName}}</span>
			<span class="delivery-number" v-if="item.putPhone!=null" @click="call(item,index)">{{item.putPhone}}</span>
			<span class="delivery-icon"><image src="../../../static/电话.png"></image></span>
			</p>
		</view>
		<view class="content-list-7">
			<p class="avatar-list">
			<span class="options">送货地址</span>
			<span class="delivery-options" >到站:{{item.destinationStation}}<span v-if="item.consigneeDetailedAddress!=null">{{item.consigneeDetailedAddress}}</span></span>
			<view class="delivery-axis"  @click="HeadMap(index,item)"><image src="../../../static/坐标.png"></image></view>
			</p>
		</view>
		<view class="content-list-7">
			<p class="avatar-list">
			<span class="abnormal-options">异常</span>
			<span class="delivery-options"></span>
			</p>
		</view>
		<view class="content-list-7">
			<p class="avatar-list">
			<span class="options">补偿</span>
			<span class="delivery-options" v-if="item.compensate!=null">{{item.compensate}}</span>
			</p>
		</view>
		<view class="content-list-13">
			<p class="avatar-list13">
			<span class="options">扣除</span>
			<span class="delivery-options" v-if="item.deductMoney!=null">{{item.deductMoney}}</span>
			</p>
		</view>
		<view class="content-list-14">
			<p class="avatar-button">
			<button class="lading" @click="showAbnormalModal(item, index)">⊙撤销</button>
			<button class="lading" @click="detailsToOrder(item, index)">√详情</button>
			</p>
		</view>
		<div class="end"></div>
		</div>
		</div>
		<view>
			<div class="end2" v-if="items.length > 0" ></div>
		</view>
		<view class="content-list-15">
			<p class="avatar-order">
			<text>合计： {{items.length}}条记录</text>
			</p>
		</view>
	</view>
	<BillModal ref="inputModal"  :businessId="businessId"  @confirm="confirm" :phone="phone"/>
	<Toast ref="toast" @del-item="delItem" :businessId="businessId" />
	</view>
</template>

<script>
	import BillModal from '@/pages/components/check/check.vue'; 
	import {getAbnormal} from '@/api/abnormal.js';
	import Toast from '@/pages/components/cancel/cancel.vue';
		// import Toast from '@/pages/components/Toast/Toast.vue';
	export default {
		components: {
			BillModal,
			Toast
		 },
		data() {
			return {
				items:[],
				businessId:0,
				queryResult:[],
				inputValue:'',
				req:{},
				phone:'',
			}
		},
		onLoad(options) {
			this.phone=options.phone
			this.userId=options.userId
			this.selectedOption=options.selectedOption
		    },
		mounted(){
			this.showInputModal();
			// getBill({contactInformation: this.phone}).then(res =>{
			// 	this.items=res.data.data
			// }).catch((error) => {
			// });
		},
		methods: {
			HeadMap(index,item){
				console.log("地图");
				const address=item.destinationStation
				uni.navigateTo({
					url: '/pagesA/index/map/map?address='+address// 请注意，这里的url应为相对路径，且以'/'开头
				});
			},
			call(item,index){
				const phoneNumber=item.putPhone
				this.callPhone(phoneNumber)
			},
			callPhone(phoneNumber) {
			        // 检查传入的电话号码是否为空或格式不正确
			        if (!phoneNumber || typeof phoneNumber !== 'string' || !/^\d+$/.test(phoneNumber)) {
			            uni.showToast({
			                title: '电话号码格式不正确',
			                icon: 'none'
			            });
			            return;
			        }
			 
			        // 使用uni.makePhoneCall发起电话拨打请求
			        uni.makePhoneCall({
			            phoneNumber: phoneNumber, // 此处填写要拨打的电话号码
			            success: function () {
			                // 用户确认拨打后，此回调会被触发
			                console.log('用户已确认拨打');
			            },
			            fail: function (err) {
			                // 用户取消拨打或拨打电话失败时，此回调会被触发
			                console.error('拨打电话失败：', err);
			                uni.showToast({
			                    title: '拨打电话失败，请检查您的设置或重试',
			                    icon: 'none'
			                });
			            }
			        });
			    },
			searchItemsByKeyword() {
				 let keyword = '';
				  if (this.inputValue !== undefined && this.inputValue !== null) {
				      keyword = this.inputValue.toLowerCase();
				  }else{
					  this.items
				  }
			        this.queryResult  = this.items.filter(item => {
			            return (
							(item.waybillNumber !== null &&item.waybillNumber.toLowerCase().includes(keyword)) ||
							(item.description !== null &&item.description.toLowerCase().includes(keyword)) ||
							(item.putUserName !== null &&item.putUserName.toLowerCase().includes(keyword)) ||
							(item.putPlane !== null &&item.putPlane.toLowerCase().includes(keyword))
			            );
			        });
					// this.items=this.queryResult;
			    },
			detailsToOrder(index){
				const selectedItem = index.businessId;
				uni.navigateTo({	
					url: '/pages/index/abnormalDetails/abnormalDetails?id='+selectedItem // 请注意，这里的url应为相对路径，且以'/'开头
				});
			},
			delItem(){
				this.$refs.inputModal.getList();
			},
			showAbnormalModal(item, index) {
				if (this.items[index].deleted===1) {
					uni.showToast({
					        title: '该订单已被撤销，无需重复操作',
					        icon: 'none',
					    });
				    return; // 如果为空，则不执行后续操作
				}
				if (this.items[index].abnormalStatus===2) {
					uni.showToast({
					        title: '该订单已被处理，不可撤销',
					        icon: 'none',
					    });
				    return; // 如果为空，则不执行后续操作
				}
				if (this.items[index].abnormalStatus===3) {
					uni.showToast({
					        title: '该订单已被完结，不可撤销',
					        icon: 'none',
					    });
				    return; // 如果为空，则不执行后续操作
				}
				this.businessId=item.id;
				console.log(item)
				this.$refs.toast.show('是否撤销');
				// this.$refs.toast.showModal('是否撤销', {
				//     onConfirm: (value) => {
				//       console.log('用户输入:', value);
				//       // 在这里处理用户输入的内容
				//     },
				//     onCancel: () => {
				//       console.log('用户取消了输入');
				//     }
				//   });
			},
			confirm(data){
				this.req.startDate=data.beginTime;
				this.req.endDate=data.endTime;
				this.req.contactInformation=this.phone
				getAbnormal(this.req).then(res=>{
					this.items=res.data.data
					this.queryResult=res.data.data
					console.log(this.items);
				}).catch(res=>{
					
				})
			},
			showInputModal(item, index) {
				console.log(this.phone)
			      this.$refs.inputModal.showModal('筛选', {
			        onConfirm: (value) => {
			          console.log('用户输入:', value);
			          // 在这里处理用户输入的内容
			        },
			        onCancel: () => {
			          console.log('用户取消了输入');
			        }
			      },this.phone);
			    },
		}
	}
</script>

<style scoped>
@import "mistake.css";
</style>
